package com.guofeng.controller;

import com.rich.common.dto.house.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.security.Principal;

/**
 * @Author: guofeng
 * @Date: 2021/08/18/14:21
 * @Description:
 */
@RestController
@Slf4j
public class TestController {

    /**
     * 获取当前用户
     *
     * @return
     */
    @GetMapping("getUserInfo")
    public Principal userInfo(Principal principal) {
        log.info("我被人调用了");
        return principal;
    }

    /**
     * 获取当前用户2
     *
     * @return
     */
    @GetMapping("getUserInfo2")
    public Authentication getUserInfo2() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }
    /**
     * 自定义用户的接口
     *
     * @return
     */
    @GetMapping("sysAdd")
    @PreAuthorize("hasAuthority('sys:add')")
    public String admin() {
        return "add的方法";
    }


    @GetMapping("testQuery")
    @PreAuthorize("hasAuthority('test:query')")
    public String testQuery() {
        return "test的方法";
    }


    /**
     * 查询数据库的接口
     *
     * @return
     */
    @GetMapping("add")
    @PreAuthorize("hasAuthority('add')")
    public Result add() {
        return  new Result("用户添加成功");
    }

    @GetMapping("delete")
    @PreAuthorize("hasAuthority('delete')")
    public Result delete() {
        return new Result("用户删除成功");
    }

    @GetMapping("update")
    @PreAuthorize("hasAuthority('update')")
    public Result update() {
        return new Result("用户修改成功");
    }

    @GetMapping("select")
    @PreAuthorize("hasAuthority('select')")
    public Result select() {
        return new Result("用户查询成功");
    }

    @GetMapping("download")
    @PreAuthorize("hasAuthority('download')")
    public Result download() {
        return new Result("用户下载成功");
    }
}
